//
//  PlistRWViewController.m
//  HappyBug
//
//  Created by liulei on 2018/12/10.
//  Copyright © 2018年 www.hc.com.cn. All rights reserved.
//

#import "PlistRWViewController.h"
#import "MineLabel.h"
#import "MineDatePicker.h"
#import "MineAlertView.h"
@interface PlistRWViewController ()

@end

@implementation PlistRWViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    UIButton *rbuttomn =[[UIButton alloc]initWithFrame:CGRectMake(20, 50, [UIScreen mainScreen].bounds.size.width-40, 120)];
    [rbuttomn addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];
    [rbuttomn setBackgroundColor:[UIColor redColor]];
    [rbuttomn setTitle:@"存Plist" forState:UIControlStateNormal];
    [self.view addSubview:rbuttomn];
    
    
    UIButton *wbuttomn =[[UIButton alloc]initWithFrame:CGRectMake(20, 190, [UIScreen mainScreen].bounds.size.width-40, 120)];
    [wbuttomn addTarget:self action:@selector(ReadClick) forControlEvents:UIControlEventTouchUpInside];

    [wbuttomn setBackgroundColor:[UIColor redColor]];
    [wbuttomn setTitle:@"取Plist" forState:UIControlStateNormal];
    [self.view addSubview:wbuttomn];
 

}

-(void)saveClick{
    NSArray *array =@[@"1",@"2",@"3",@"4",@"5",@"6"];
    NSMutableDictionary *dic =[[NSMutableDictionary alloc]init];
    [dic setValue:@"2!" forKey:@"111a"];
    [dic setValue:@"3@" forKey:@"2222d"];
    [dic setValue:@"3$" forKey:@"333f"];
    [dic setValue:@"4!" forKey:@"444f"];

    NSArray  *pathurl=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *plistPath1 = [pathurl objectAtIndex:0];
    //得到完整的文件名
    NSString *filename=[plistPath1 stringByAppendingPathComponent:@"plistdemo.plist"];
    NSLog(@"Savefilename:%@",filename);
    //写入
    [dic writeToFile:filename atomically:YES];
    
    
}

-(void)ReadClick{
    //获取需要读取数据plist路径
    NSString *plistPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"plistdemo.plist"];
    
    //将plist文件中数据转换成数组形式输出（要预先知道plist中数据类型，否则无法读出）
//    NSArray *products = [NSArray arrayWithContentsOfFile:plistPath];
//    NSLog(@"Read:%@", products);
//
    NSDictionary *productsdic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    NSLog(@"Read:%@", productsdic);
   
}


@end
